<template>
  <div class="history-hot">
    <div class="his-hot">
      <div class="hd">
        <h4>历史记录</h4>
        <van-icon @click="clear()" name="delete-o" />
      </div>
      <div class="tag">
        <van-tag
          plain
          type="default"
          v-for="(v, k) in historyKeywordList"
          :key="k"
          @click="fun(v)"
          >{{ v }}</van-tag
        >
      </div>
    </div>
    <div class="his-hot">
      <div class="hd">
        <h4>热门搜索</h4>
      </div>
      <div class="tag">
        <van-tag
          :color="v.is_hot ? 'red' : ''"
          plain
          type="default"
          v-for="(v, k) in hotKeywordList"
          :key="k"
          @click="hot(v.keyword)"
          >{{ v.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHis } from "@/request/api";

export default {
  data() {
    return {};
  },
  // 清除历史记录
  methods: {
    clear() {
      ClearHis().then((res) => {
        if (res.errno === 0) {
          console.log("删除成功");
          this.$router.go(0);
        }
        // console.log(res);
      });
      // 轻提示
      this.$toast.success("删除成功");
    },
    fun(v) {
      // console.log(v);
      this.$emit("change", v);
    },
    hot(v) {
      this.$emit("change", v);
    },
  },
  props: ["historyKeywordList", "hotKeywordList"],
};
</script>

<style lang="less">
.his-hot {
  background-color: #fff;
  margin-bottom: 0.2rem;
  padding: 2%;
  .hd {
    display: flex;
    justify-content: space-between;
    font-size: 0.15rem;
    padding-bottom: 2%;
  }
  .van-tag {
    margin-right: 0.1rem;
    margin-top: 0.1rem;
    padding: 0.01rem;
  }
  .tag {
    margin-bottom: 0.15rem;
  }
}
</style>